package com.cddata;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.cddata.util.DBOperation;

@SuppressWarnings("serial")
public class MainWindow extends JFrame {

	public MainWindow() {
		super( "CONTENT MANAGEMENT SYSTEM" );
		Toolkit theKit = getToolkit(); // Get the window toolkit
		Dimension wndSize = theKit.getScreenSize(); // Get screen size
		// Set the position to screen center & size to half screen size
		//		mainWindow.setBounds(wndSize.width/4, wndSize.height/4, // Position
		//							 wndSize.width/2, wndSize.height/2); // Size
		setBounds(wndSize.width/6, wndSize.height/6, // Position
				wndSize.width/2+200, wndSize.height/2+200); // Size
                
                setLocationRelativeTo(null);
                
		DBOperation.getHelperBean().setMainWindowHieght(getHeight());
		DBOperation.getHelperBean().setMainWindowWidth(getWidth());
		contentPane = (JPanel) getContentPane();
		contentPane.setBackground(Color.LIGHT_GRAY);
		contentPane.add( new Header(), BorderLayout.NORTH);
		menuData();
		DBOperation.getHelperBean().setDataPanel( menuAndDataPanel );
	}

	public static void logoff() {
		menuAndDataPanel = DBOperation.getHelperBean().getDataPanel();
		contentPane.remove(menuAndDataPanel);
		DBOperation.getHelperBean().setDataPanel(null) ;
		menuData();
	}

	private static void menuData() {
		DBOperation.getHelperBean().setDataPanel(new JPanel());
		menuAndDataPanel = DBOperation.getHelperBean().getDataPanel();
		menuAndDataPanel.setLayout(new BoxLayout(menuAndDataPanel, BoxLayout.X_AXIS));
		menuAndDataPanel.add(new Login(),BorderLayout.CENTER);
		contentPane.add(menuAndDataPanel);
	}
	
	public static void main(String[] args) {
		HelperBean helperBean = new HelperBean();
		DBOperation.setHelperBean( helperBean );
		MainWindow mainWindow = new MainWindow();
		mainWindow.setDefaultCloseOperation(EXIT_ON_CLOSE);
		mainWindow.setVisible(true);
	}

	private static JPanel contentPane = null;
	private static JPanel menuAndDataPanel = null;
}
